package com.community.system.controller;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.community.common.annotation.Log;
import com.community.common.core.controller.BaseController;
import com.community.common.core.domain.AjaxResult;
import com.community.common.enums.BusinessType;
import com.community.system.domain.PatrolRoute;
import com.community.system.service.IPatrolRouteService;
import com.community.common.utils.poi.ExcelUtil;
import com.community.common.core.page.TableDataInfo;

/**
 * routeController
 * 
 * @author ruoyi
 * @date 2025-10-27
 */
@RestController
@RequestMapping("/system/route")
public class PatrolRouteController extends BaseController
{
    @Autowired
    private IPatrolRouteService patrolRouteService;

    /**
     * 查询route列表
     */
    @PreAuthorize("@ss.hasPermi('system:route:list')")
    @GetMapping("/list")
    public TableDataInfo list(PatrolRoute patrolRoute)
    {
        startPage();
        List<PatrolRoute> list = patrolRouteService.selectPatrolRouteList(patrolRoute);
        return getDataTable(list);
    }

    /**
     * 导出route列表
     */
    @PreAuthorize("@ss.hasPermi('system:route:export')")
    @Log(title = "route", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PatrolRoute patrolRoute)
    {
        List<PatrolRoute> list = patrolRouteService.selectPatrolRouteList(patrolRoute);
        ExcelUtil<PatrolRoute> util = new ExcelUtil<PatrolRoute>(PatrolRoute.class);
        util.exportExcel(response, list, "route数据");
    }

    /**
     * 获取route详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:route:query')")
    @GetMapping(value = "/{routeId}")
    public AjaxResult getInfo(@PathVariable("routeId") Long routeId)
    {
        return success(patrolRouteService.selectPatrolRouteByRouteId(routeId));
    }

    /**
     * 新增route
     */
    @PreAuthorize("@ss.hasPermi('system:route:add')")
    @Log(title = "route", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PatrolRoute patrolRoute)
    {
        return toAjax(patrolRouteService.insertPatrolRoute(patrolRoute));
    }

    /**
     * 修改route
     */
    @PreAuthorize("@ss.hasPermi('system:route:edit')")
    @Log(title = "route", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PatrolRoute patrolRoute)
    {
        return toAjax(patrolRouteService.updatePatrolRoute(patrolRoute));
    }

    /**
     * 删除route
     */
    @PreAuthorize("@ss.hasPermi('system:route:remove')")
    @Log(title = "route", businessType = BusinessType.DELETE)
	@DeleteMapping("/{routeIds}")
    public AjaxResult remove(@PathVariable Long[] routeIds)
    {
        return toAjax(patrolRouteService.deletePatrolRouteByRouteIds(routeIds));
    }
}
